<?php
/**
 * Created by PhpStorm.
 * User: spring
 * Date: 18-11-30
 * Time: 上午10:34
 */

namespace App\Services;


use App\Models\Purview;

class PurviewService
{
    public static function purviewAll(){
        return $purview_all = Purview::orderBy("lft","asc")->get();
    }
    /**
     * 根据条件获取权限列表
     * @param int $status
     * @param string $f_main
     * @param string $ids_str
     * @return mixed
     */
    public static function purviewAllByOpt($status="", $f_main = "", $ids_str = ""){
        $map = array();
        if($status !== ""){
            $map[] = array("status","=",$status);
        }
        if($f_main){
            $map[] = array("f_main","=",$f_main);
        }
        if($ids_str){
            $ids_str = explode(",",$ids_str);
            $purview_all = Purview::where($map)->whereIn('id',$ids_str)->orderBy("lft","asc")->get();
        }else{
            $purview_all = Purview::where($map)->orderBy("lft","asc")->get();
        }

        return $purview_all;
    }

    /**
     * 获取当前父类下最后一个数据
     * @param $parent
     */
    public static function getLastByParent($parent){
        $info = Purview::where('parent',$parent)->orderBy("id","desc")->first();
        if(!$info){
            return false;
        }else{
            return $info;
        }
    }
}